// TerrainEditor.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "TerrainEditor.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "TerrainEditorDoc.h"
#include "OpenGLView.h"
#include "2DMapView.h"
#include "3DArcBallView.h"
#include "AboutDlg.h"
#include <direct.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTerrainEditorApp

BEGIN_MESSAGE_MAP(CTerrainEditorApp, CWinApp)
	//{{AFX_MSG_MAP(CTerrainEditorApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTerrainEditorApp construction

CTerrainEditorApp::CTerrainEditorApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTerrainEditorApp object

CTerrainEditorApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CTerrainEditorApp initialization

BOOL CTerrainEditorApp::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.

//	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

//	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Other accessory views that are used for different types of editing
	// or viewing. The IDR values for the views below have been edited
	// to remove the CDocTemplate::fileNewName section of the string in
	// order to prevent the app from thinking there are two different documents.
	// The document template resource ID associates three specific resources with 
	// a given document template object: 
	// (1) icon resource
	// (2) menu resource: When the user activates a particular frame window, MFC 
	//     replaces the main application menu with the menu resource associated with 
	//     the document template resource ID of the active frame window object.
	// (3) string resource: This string is concatnation of seven substrings separated 
	//     by "\n". These are frame window's title (windowTitle), default name assigned 
	//     to new document (docName), descriptive name for document of this type 
	//     (fileNewName), descriptive name for document of this type and associated 
	//     default file type (filterName), default file name extension (filterExt), 
	//     name registered in the registry for this type of document ( regFileTypeId), 
	//     and human readable name for this file type appears in windows explorer 
	//     (regFileTypeName). For example - 
	//     \nMDIApp\nMDIApp\n\n\nMDIApp.Document\nMDIApp Document
	//     windowTitle = "", docName = "MDIApp", fileNewName = "MDIApp", filterName = "", 
	//     filterExt = "", regFileTypeID = MDIApp.Document, and regFileTypeName = MDIApp Document. 

	m_p2DMapViewDocTemplate = new CMultiDocTemplate(IDR_TerrainDoc2DMapView,
												    RUNTIME_CLASS(CTerrainEditorDoc),
												    RUNTIME_CLASS(CChildFrame),
												    RUNTIME_CLASS(C2DMapView));

	m_p3DArcBallViewDocTemplate = new CMultiDocTemplate(IDR_TerrainDoc3DArcBallView,
														  RUNTIME_CLASS(CTerrainEditorDoc),
														  RUNTIME_CLASS(CChildFrame),
														  RUNTIME_CLASS(C3DArcBallView));

	AddDocTemplate(m_p2DMapViewDocTemplate);
	AddDocTemplate(m_p3DArcBallViewDocTemplate);

	// create main MDI Frame window
	m_pMainFrame = new CMainFrame;
	if (!m_pMainFrame->LoadFrame(IDR_MainFrame)) return FALSE;
	m_pMainWnd = m_pMainFrame;

	// Parse command line for standard shell commands, DDE, file open

//	CCommandLineInfo cmdInfo;
//	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line

//	if (!ProcessShellCommand(cmdInfo)) return FALSE;

	// The main window has been initialized, so show and update it.
	m_pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
	m_pMainFrame->UpdateWindow();

	// Grab the working directory for file operations

	_getcwd(m_cMainFolder, 255);

	return TRUE;
}

// App command to run the dialog
void CTerrainEditorApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CTerrainEditorApp message handlers

